﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using ZK.Common;
using ZK.HardWareBLL;

namespace ZK.YHP_TransManage.Test
{
    public partial class 远瑞通室外读卡器test : Form
    {
        private HardWareBLL.YRTReaderBLL reader;

        //盘存操作前，需要先设置工作天线，用于标识当前是否在执行盘存操作
        public 远瑞通室外读卡器test()
        {
            InitializeComponent();
        }

        private void getDataCallback(string epc)
        {
            SetMess(epc);
        }

        public void SetMess(string str)
        {
            this.Invoke(new Action(() =>
            {
                textBox1.AppendText(str + "\n");
            }));
        }

        /// <summary>
        /// 连接按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //初始化访问读写器实例
            Models.TerminalM terminalM = new Models.TerminalM();
            terminalM.ip = textBoxip.Text.Trim();
            terminalM.port = 4001;
            reader = new HardWareBLL.YRTReaderBLL(terminalM);

            //回调函数
            reader.getDataCallbackEvent = getDataCallback;
            Common.ShowBlackBox.WriteLine("2 set connect success");
        }

        /// <summary>
        /// 开始事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            reader.Open();
            Common.ShowBlackBox.WriteLine("2 set open success");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            reader.Close();
            Common.ShowBlackBox.WriteLine("2 set close");
        }
        //set
        private void button4_Click(object sender, EventArgs e)
        {
            Common.HaredWareCommonM haredWareCommonM = new HaredWareCommonM()
            {
                Ip = textBoxip.Text.Trim()
            };
            Common.IConfig.GetSetCardReader = haredWareCommonM;
            Common.ShowBlackBox.WriteLine("2 set success");
        }

    }

}
